package com.sgcc.ln.pmos.e_ln_mall.activity;


import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.sgcc.ln.pmos.arouter.mall.MallArouterPath;
import com.sgcc.ln.pmos.common.base.MvpBaseRecycleActivity;
import com.sgcc.ln.pmos.common.bean.EventCenter;
import com.sgcc.ln.pmos.common.bean.RatioCurveBean;
import com.sgcc.ln.pmos.common.utils.ArguConstant;
import com.sgcc.ln.pmos.common.utils.ImmersionBarUtils;
import com.sgcc.pmos.nativesdk.R;
import com.sgcc.ln.pmos.e_ln_mall.adapter.SelectCurveAdapter;
import com.sgcc.ln.pmos.e_ln_mall.contract.SelectCurveContract;
import com.sgcc.ln.pmos.e_ln_mall.presenter.SelectCurvePresenter;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.List;

@Route(path = MallArouterPath.MALL_SELECT_CURVE)
public class SelectCurveActivity extends MvpBaseRecycleActivity<RatioCurveBean.Bean, SelectCurvePresenter> implements SelectCurveContract.View {


    private TextView mTvComparisonListFooterStart;
    private LinearLayout mLLComparisonListFooterStart;

    @Autowired
    int position = 0;

    @Autowired
    ArrayList<RatioCurveBean.Bean> ratioCurveList;
    private RatioCurveBean.Bean selectBean;


    @Override
    protected void initViews() {
        super.initViews();
        ImmersionBarUtils.initBaseBar(this);
        mTvComparisonListFooterStart = findViewById(R.id.tv_comparisonListFooter_start);
        mLLComparisonListFooterStart = findViewById(R.id.ll_comparisonListFooter_start);
        mTvComparisonListFooterStart.setText("保存");
        refreshLayout.setEnablePureScrollMode(true);


    }


    @Override
    protected void initData() {
        super.initData();
        mLLComparisonListFooterStart.setOnClickListener(view -> {
            EventBus.getDefault().post(new EventCenter<>(ArguConstant.SELECT_CURVE_BACK, selectBean));
            finish();
        });
    }

    @Override
    public String getTitleText() {
        return "选择曲线";
    }

    @Override
    public View getFooterLayout(RelativeLayout parent) {
        return getLayoutInflater().inflate(R.layout.footer_comparison_list_layout, parent, false);
    }


    @Override
    public BaseQuickAdapter getAdapter() {
        SelectCurveAdapter selectCurveAdapter = new SelectCurveAdapter();
        selectCurveAdapter.setOnItemClickListener((position, s) -> {

            List<RatioCurveBean.Bean> data = selectCurveAdapter.getData();
            selectBean = data.get(position);
            for (int i = 0; i < data.size(); i++) {
                data.get(i).setSelect(i == position);
            }
            selectCurveAdapter.notifyDataSetChanged();
        });
        return selectCurveAdapter;
    }

    @Override
    protected SelectCurvePresenter createPresenter() {
        return new SelectCurvePresenter();
    }

    @Override
    public void querySuccess() {

    }

    @Override
    public void queryFailed() {

    }

    @Override
    public void getDataRequest(int listSize, boolean isLoading) {
        super.getDataRequest(listSize, isLoading);
        if (null != ratioCurveList && ratioCurveList.size() > 0) {
            selectBean = ratioCurveList.get(position);
            selectBean.setSelect(true);
        }
        loadSuccess(false, ratioCurveList);

    }


}